package com.demo.controller;

import com.demo.model.SysDic;
import com.demo.service.SysDicService;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
@Log4j2
public class SysDicController {

    @Resource
    private SysDicService service;

    @RequestMapping(value = "sys_dic_view")
    public String sys_dic_view(String dickeys, HttpServletRequest request){
        if(null==dickeys){
            dickeys = "";
        }
        SysDic d = new SysDic();
        d.setDickeys(dickeys);
        service.findAll(d,request);
        request.setAttribute("dickeys",dickeys);
        return "index/sys_dic/view";
    }

    @RequestMapping(value = "sys_dic_update_flag_open")
    public String sys_dic_update_flag_open(String id,HttpServletRequest request){
        SysDic d = new SysDic();
        d.setId(Integer.parseInt(id));
        d.setFlag("0");
        service.update_dic_flag(d);
        return "redirect:sys_dic_view";
    }

    @RequestMapping(value = "sys_dic_update_flag_close")
    public String sys_dic_update_flag_close(String id,HttpServletRequest request){
        SysDic d = new SysDic();
        d.setId(Integer.parseInt(id));
        d.setFlag("1");
        service.update_dic_flag(d);
        return "redirect:sys_dic_view";
    }

    @RequestMapping(value = "sys_dic_pre_up")
    public String sys_dic_pre_up(String id,HttpServletRequest request){
        SysDic d = service.findById(id);
        request.setAttribute("d",d);
        return "index/sys_dic/update";
    }

    @RequestMapping(value = "sys_dic_up")
    public String sys_dic_up(SysDic d,HttpServletRequest request){
        boolean b = service.update(d);
        request.setAttribute("b",b);
        return "index/sys_dic/update";
    }

    @RequestMapping(value = "sys_dic_pre_save")
    public String sys_dic_pre_save(){
        return "index/sys_dic/save";
    }

    @RequestMapping(value = "sys_dic_save")
    public String sys_dic_save(SysDic d,HttpServletRequest request){
        boolean b = service.save(d);
        request.setAttribute("b",b);
        return "index/sys_dic/save";
    }

    @RequestMapping(value = "sys_dic_del")
    public String sys_dic_del(String id,HttpServletRequest request){
        service.del(id);
        return "redirect:sys_dic_view";
    }
}
